package com.superman.supermarket.client.composite.mycouponlist;

import java.util.Map;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.superman.supermarket.client.composite.storecoupon.StoreCouponModule;
import com.superman.supermarket.client.constant.StoreCouponConstants;

/**
 * 我的优惠券模块
 * 
 * @author superman
 * @version 2018年8月19日下午10:50:39
 */
public class CouponListCellModule extends StoreCouponModule {

	private int limitType;
	private Map<String, Object> map;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月19日 下午10:50:57
	 */
	public CouponListCellModule() {
		getbtn.setText("去使用");
		wrapperpanel.getElement().getStyle().setProperty("marginLeft", "0.4rem");

		getbtn.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				toUse();
			}
		});
	}

	@Override
	public void setData(Map<String, Object> map) {

		this.map = map;
		String nameStr = String.valueOf(map.get("NAME"));
		namehtml.setText(nameStr);

		limitType = (int) Double.parseDouble(String.valueOf(map.get("SCENE_TYPE")));

		limithtml.setText(StoreCouponConstants.getLimitDescByType(limitType));

		String startTime = String.valueOf(map.get("USE_START"));
		String endTime = String.valueOf(map.get("DEADLINE"));
		String timeStr = startTime + "至" + endTime;
		timehtml.setText(timeStr);

	}

	private void toUse() {
		CouponUseJumperFactory.toUse(map);
	}

}
